using System;
using UnityEngine;

public class Generator : MonoBehaviour
{
	public static Generator instance;

	public Pool pool;

	private GameObject go;

	private void Awake()
	{
		instance = this;
	}

	private int FindEmptyEnemyArrayNumber()
	{
		for (int i = 0; i < 100; i++)
		{
			if (!AllObjectsInfo.SCRT_EnemyList[i])
			{
				return i;
			}
		}
		return -999;
	}

	public void SpawnObj(int kind, Vector2 pos, float[] data = null, Transform TF_Target = null)
	{
		if (pool.goList[kind, 0].name.Contains("Enemy"))
		{
			for (int i = 0; i < pool.prefabAmountList[kind]; i++)
			{
				go = pool.goList[kind, i];
				if (!go.activeSelf)
				{
					go.SetActive(true);
					go.transform.position = pos;
					int num = FindEmptyEnemyArrayNumber();
					if (num == -999)
					{
						Debug.Log("ERROR : Full Of Enemy Script!!");
						return;
					}
					AllObjectsInfo.SCRT_EnemyList[num] = go.GetComponent<EnemySelecter>();
					AllObjectsInfo.SCRT_EnemyList[num].Init(num, (data != null) ? ((int)data[0]) : 0);
					return;
				}
			}
		}
		int num2 = -999;
		for (int j = 0; j < pool.prefabAmountList[kind]; j++)
		{
			go = pool.goList[kind, j];
			if (!go.activeSelf)
			{
				go.SetActive(true);
				go.transform.position = pos;
				num2 = j;
				break;
			}
		}
		if (num2 == -999)
		{
			return;
		}
		try
		{
			switch (kind)
			{
			case 3:
				AllObjectsInfo.SCRT_GrenadeList[num2].Init(new Vector2(data[0], data[1]));
				break;
			case 7:
				AllObjectsInfo.SCRT_DamageTextList[num2].Show(pos, (int)data[0], (int)data[1]);
				break;
			case 8:
				AllObjectsInfo.SCRT_EnergeBallList[num2].Init(new float[3]
				{
					data[0],
					data[1],
					data[2]
				});
				break;
			case 12:
				AllObjectsInfo.SCRT_Arrow1List[num2].Init(new float[3]
				{
					data[0],
					data[1],
					data[2]
				});
				break;
			case 20:
				AllObjectsInfo.SCRT_Lightning1List[num2].Init(new float[3]
				{
					data[0],
					data[1],
					data[2]
				});
				break;
			case 23:
				AllObjectsInfo.SCRT_FreezingTrapList[num2].Init(new float[4]
				{
					data[0],
					data[1],
					data[2],
					data[3]
				});
				break;
			case 24:
				AllObjectsInfo.SCRT_HUDtargetingCircleList[num2].Init(TF_Target);
				break;
			case 25:
				AllObjectsInfo.SCRT_ShockStunRingList[num2].Init(TF_Target);
				break;
			case 26:
				AllObjectsInfo.SCRT_HUDOutOfScreenTheTarget[num2].Init(TF_Target);
				break;
			case 28:
				AllObjectsInfo.SCRT_HommingMagic1[num2].Init(TF_Target, data[0]);
				break;
			}
		}
		catch (Exception ex)
		{
			Debug.Log("SpawnObj error " + kind + " (" + num2 + ") : " + ex);
		}
	}
}
